import React, { Component } from 'react';
import Taro from '@tarojs/taro';
import { View, Text, Button,Image } from '@tarojs/components';
import './index.scss'
import { queryWrongTypeList } from '@/services/api/xiaoyiAccExam';
import { findMapsByFieldNameAndDictItemName } from '@/services/api/common';

class XiaoYiWrongQuestionList extends Component {

    config = {
        navigationBarTitleText: ''
    }

    state = {
        typeListData: []
    }

    componentWillMount() {
        this.requestData()
     }
    componentDidMount() { }
    componentWillReceiveProps(nextProps, nextContext) { }
    componentWillUnmount() { }


    requestData(){
        const { typeListData } = this.state
        queryWrongTypeList().then((resp) => {
            if(resp.code === 200){
                var data = resp.data;
                var types = findMapsByFieldNameAndDictItemName('examination_questionnaire_type')
                for (let index = 0; index < types.length; index++) {
                    const typeItem = types[index];
                    for (let index = 0; index < Object.keys(data).length; index++) {
                        const element = Object.keys(data)[index];
                        if(typeItem.dictItemValue === element){
                            console.log(element)
                            console.log(data[element])
                            typeListData.push({'name':typeItem.dictItemName,'data':data[element]})
                        }
                    }
                }
                this.setState({typeListData:typeListData})
            }
        })
    }


    gotoDetail(value){
        Taro.preload(value)
        Taro.navigateTo({url:'/xiaoyiAccExam/analysis/index'})
    }

    render() {
        const { typeListData } = this.state
        return (
            <View className='page'>

                {
                    typeListData.map((item,index) => {
                        console.log(item)
                        return     <View className='item'>
                        <View className='top'>
                           <View className='sq'></View>
                           <Text className='name'>{item['name']}</Text>
                           <Text space='nbsp' decode>{`共&nbsp;${item['data'].length}&nbsp;题`}</Text>
                        </View>
                        <View className='review-button' onClick={(e) => this.gotoDetail(item)}>
                            <Text>错题回顾</Text>
                            <Image src={require('@/assets/icons/public/public_arrow_right.svg')}></Image>
                        </View>
                    </View>
                    })
                }
            
               
            </View>
        );
    }
}
export default XiaoYiWrongQuestionList;